package com.luokun.vue_shop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luokun.vue_shop.api.Json;
import com.luokun.vue_shop.api.Result;
import com.luokun.vue_shop.entity.SpUser;
import com.luokun.vue_shop.service.ISpUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin(origins="*")
@RestController
@Slf4j
@RequestMapping("/SpUser")
public class SpUserController {
    @Autowired
    private ISpUserService iSpUserService;


    @RequestMapping("/login")
    public void login(@RequestBody SpUser spUser, HttpServletResponse response) throws Exception {
        List<SpUser> list=new ArrayList<>();
        QueryWrapper<SpUser> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",spUser.getUsername()).eq("password",spUser.getPassword());
         list=iSpUserService.list(queryWrapper);
         if (list.isEmpty()){
             Json.toJson(new Result(false,7000,"没有数据",null),response);
             return;
         }
        Result result = new Result(true,200,"成功",list);
        Json.toJson(result,response);

    }











}
